package com.team.arms.tijian.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.team.arms.common.Result;
import com.team.arms.common.ry.core.domain.AjaxResult;
import com.team.arms.tijian.entity.dto.HealthFailedDTO;
import com.team.arms.tijian.entity.vo.AllVO;
import com.team.arms.tijian.entity.vo.HealthFailedVo;
import com.team.arms.tijian.mapper.SysHealthExaminationMapper;
import com.team.arms.tijian.mapper.SysHealthFailedMapper;
import com.team.arms.tijian.service.ISysHealthFailedService;
import com.team.arms.utils.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 体检不合格项信息表 前端控制器
 * </p>
 *
 * @author Huazige
 * @since 2022-06-02
 */
@RestController
@RequestMapping("/sysHealthFailed")
@Api(tags="体检-不合格模块")
@CrossOrigin
public class SysHealthFailedController {
    @Resource
    ISysHealthFailedService iSysHealthFailedService;

    @Resource
    SysHealthFailedMapper sysHealthFailedMapper;
    @Autowired
    SysHealthExaminationMapper sysHealthExaminationMapper;

    @ApiOperation("获取体检不合格信息")
//    @Log(title = "政审信息", businessType = BusinessType.)
    @GetMapping(value = "/get")
    public AjaxResult selectpltc() {

        List<HealthFailedVo> list = iSysHealthFailedService.selectall();
//

        if (list!=null){
            return AjaxResult.success("查询成功",list) ;
        }
        else {
            return AjaxResult.error("查询失败");
        }


    }
    @ApiOperation(value = "体检不合格-下拉框查找")
    @GetMapping("/found")
    //
//    三张表的数据，删除的时候，直接这三个都删除
    public AjaxResult found(@RequestParam(value = "查询的字段") String field , @RequestParam(value = "查询的内容")String content) {
        //也可以直接从redis缓冲中去调用一个foreach循环拿到对应name的数据

        List<HealthFailedVo> list = sysHealthFailedMapper.selectbyname(field,content);
        if (list.size()>0){
            return AjaxResult.success("姓名查找成功",list);
        }else {
            return    AjaxResult.success("没有找到姓名信息");
        }

    }


//    @ApiOperation("复检")
////    @Log(title = "政审信息", businessType = BusinessType.)
//    @PostMapping(value = "/fujian")
//    public AjaxResult send( @RequestParam("poliInfoId")String id) {
//        String   state ="复检";
//        SysHealthFailed FailedPerson = iSysHealthFailedService.getById(id);
////        FailedPerson.set;//少了个字段的状态
//
//        QueryWrapper<SysHealthFailed> wrapper = new QueryWrapper();
//        wrapper.eq("poli_info_id",id);
//        boolean b =   iSysHealthFailedService.update(FailedPerson,wrapper);//前新后旧
//        return b ? AjaxResult.success("该数据进入复检中",FailedPerson) : AjaxResult.error("复检状态修改失败");
//    }


    @ApiOperation("获取某个人的详情内容")
    @GetMapping(value = "/getall/{examineId}}")
    public AjaxResult selectall(
            @PathVariable("examineId")String examineId
    ) {

        List<AllVO> list = sysHealthExaminationMapper.select(examineId);
        return AjaxResult.success("查询成功",list) ;

    }

    @ApiOperation("复检/单个+批量删除")
    @DeleteMapping("/examineId")
    public Result deleteInformation(
            @ApiParam("体检编号") @RequestParam("examineId")List<String> deletelist ) {
        int delete =0;

        for ( String id:deletelist
        ) {
            QueryWrapper<entity.SysHealthExamination> wrapper = new QueryWrapper();
            wrapper.eq("examine_id",id);

                   delete = sysHealthExaminationMapper.delete(wrapper);


               }
        if (delete>0){
            return Result.success("批量删除成功");
        }
        return Result.error("批量删除失败");
    }

    @ApiOperation("高级检索")
    @PutMapping("/find/{pageNum}/{pageSize}")
    public Result updateInformation(
            @ApiParam("当前页数")       @PathVariable("pageNum")Integer pageNum,
            @ApiParam("每页的数据量")       @PathVariable("pageSize")Integer pageSize,
            @RequestBody HealthFailedDTO healthFailedDTO){
        List<HealthFailedVo> select = sysHealthFailedMapper.select(healthFailedDTO);


        Page page = PageUtil.list2Page(select, pageNum, pageSize);
        return page !=null ? Result.success("分页成功").data(page): Result.error("分页失败");
    }
}




